package mx.netbrain.util;

import org.w3c.dom.Element;

public class ReadXML {

	private String driver;
	private String pass;
	private String url;
	private String user;

	public ReadXML() {
		org.w3c.dom.Document dom = null;
		javax.xml.parsers.DocumentBuilderFactory dbf;
		javax.xml.parsers.DocumentBuilder db;
		dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
		try {
			FileWebUtil pathWeb = new FileWebUtil();
			String path = pathWeb.getWebInfPath();
			db = dbf.newDocumentBuilder();
			dom = db.parse(path + "/classes/hibernate.cfg.xml");
		} catch (Exception e) {
			System.out.println("Error ===> " + e);
		}
		org.w3c.dom.Element rootElement = dom.getDocumentElement();
		org.w3c.dom.NodeList nodeList = rootElement
				.getElementsByTagName("property");
		if (nodeList != null && nodeList.getLength() > 0) {
			for (int i = 0; i < nodeList.getLength(); i++) {
				org.w3c.dom.Element element = (Element) nodeList.item(i);
				String attr = element.getAttribute("name");
				if (attr.equals("hibernate.connection.driver_class")) {
					driver = element.getFirstChild().getNodeValue();
				} else if (attr.equals("hibernate.connection.password")) {
					pass = element.getFirstChild().getNodeValue();
				} else if (attr.equals("hibernate.connection.url")) {
					url = element.getFirstChild().getNodeValue();
				} else if (attr.equals("hibernate.connection.username")) {
					user = element.getFirstChild().getNodeValue();
				}
			}
		}
	}

	public String getDriver() {
		return driver;
	}

	public void setDriver(String driver) {
		this.driver = driver;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

}
